package com.yuwubao.uav.tool.service.impl;

import com.yuwubao.framework.bean.PageData;
import com.yuwubao.uav.tool.mapper.SpecialMapper;
import com.yuwubao.uav.tool.service.SpecialService;
import com.yuwubao.uav.tool.util.StringUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 *
 */
@Service
public class SpecialServiceImpl implements SpecialService {

    private static final Logger logger = LogManager.getLogger(SpecialServiceImpl.class.getName());

    @Resource
    private SpecialMapper specialMapper;

    @Override
    public void deleteSpecial(PageData pageData) throws Exception {
        try{
            String ids = pageData.get("ids") == null ? "" : pageData.getString("ids");
            if (StringUtil.isNotNvlOrBlank(ids)) {
                String[] idArr = ids.split(",");
                if (idArr != null && idArr.length>0) {
                    pageData.put("idArr",idArr);
                    specialMapper.deleteSpecial(pageData);

                }
            }
        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void updateSpecial(PageData pageData) throws Exception {
        try{
            specialMapper.updateSpecial(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void disableOrEnableSpecial(PageData pageData) throws Exception {
        try{
            String ids = pageData.get("ids") == null ? "" : pageData.getString("ids");
            if (StringUtil.isNotNvlOrBlank(ids)) {
                String[] idArr = ids.split(",");
                if (idArr != null && idArr.length>0) {
                    pageData.put("idArr",idArr);
                    specialMapper.disableOrEnableSpecial(pageData);

                }
            }
        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void disableOrEnableSpecialType(PageData pageData) throws Exception {
        try{
            String ids = pageData.get("ids") == null ? "" : pageData.getString("ids");
            if (StringUtil.isNotNvlOrBlank(ids)) {
                String[] idArr = ids.split(",");
                if (idArr != null && idArr.length>0) {
                    pageData.put("idArr",idArr);
                    specialMapper.disableOrEnableSpecialType(pageData);

                }
            }
        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void addSpecial(PageData pageData) throws Exception {
        try{
            specialMapper.addSpecial(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
    }

    @Override
    public List<PageData> listSpecial(PageData pageData) throws Exception {
        try{
            return specialMapper.listSpecial(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return null;
    }
    @Override
    public int listSpecialCount(PageData pageData) throws Exception {
        try{
            return specialMapper.listSpecialCount(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return 0;
    }

    @Override
    public void deleteSpecialType(PageData pageData) throws Exception {
        try{

            String ids = pageData.get("ids") == null ? "" : pageData.getString("ids");

            if (StringUtil.isNotNvlOrBlank(ids)) {
                String[] idArr = ids.split(",");
                if (idArr != null && idArr.length>0) {
                    pageData.put("idArr",idArr);
                    specialMapper.deleteSpecialType(pageData);

                }
            }


        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void updateSpecialType(PageData pageData) throws Exception {
        try{
            specialMapper.updateSpecialType(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
    }

    @Override
    public void addSpecialType(PageData pageData) throws Exception {
        try{
            String names = pageData.get("names") == null ? "" : pageData.getString("names");
            if (StringUtil.isNotNvlOrBlank(names)) {
                String[] nameArr = names.split(",");
                if (nameArr != null && nameArr.length>0) {
                    for (String name : nameArr) {
                        pageData.put("name",name);
                        specialMapper.addSpecialType(pageData);
                    }
                }
            }
        }catch (Exception e) {
            logger.debug("",e);
        }
    }

    @Override
    public List<PageData> listSpecialType(PageData pageData) throws Exception {
        try{
            return specialMapper.listSpecialType(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return null;
    }
    @Override
    public List<PageData> listSpecialTypeAll(PageData pageData) throws Exception {
        try{
            return specialMapper.listSpecialTypeAll(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return null;
    }
    @Override
    public int listSpecialTypeCount(PageData pageData) throws Exception {
        try{
            return specialMapper.listSpecialTypeCount(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return 0;
    }

    //父类型

    @Override
    public void disableOrEnableSpecialTypeFather(PageData pageData) throws Exception {
        try{
            String ids = pageData.get("ids") == null ? "" : pageData.getString("ids");
            if (StringUtil.isNotNvlOrBlank(ids)) {
                String[] idArr = ids.split(",");
                if (idArr != null && idArr.length>0) {
                    pageData.put("idArr",idArr);
                    specialMapper.disableOrEnableSpecialTypeFather(pageData);

                }
            }
        }catch (Exception e) {
            logger.debug("",e);
        }
    }

    @Override
    public void deleteSpecialTypeFather(PageData pageData) throws Exception {
        try{

            String ids = pageData.get("ids") == null ? "" : pageData.getString("ids");

            if (StringUtil.isNotNvlOrBlank(ids)) {
                String[] idArr = ids.split(",");
                if (idArr != null && idArr.length>0) {
                    pageData.put("idArr",idArr);
                    specialMapper.deleteSpecialTypeFather(pageData);

                }
            }


        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void updateSpecialTypeFather(PageData pageData) throws Exception {
        try{
            specialMapper.updateSpecialTypeFather(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
    }

    @Override
    public void addSpecialTypeFather(PageData pageData) throws Exception {
        try{
            String names = pageData.get("names") == null ? "" : pageData.getString("names");
            if (StringUtil.isNotNvlOrBlank(names)) {
                String[] nameArr = names.split(",");
                if (nameArr != null && nameArr.length>0) {
                    for (String name : nameArr) {
                        pageData.put("name",name);
                        specialMapper.addSpecialTypeFather(pageData);
                    }
                }
            }
        }catch (Exception e) {
            logger.debug("",e);
        }
    }

    @Override
    public List<PageData> listSpecialTypeFather(PageData pageData) throws Exception {
        try{
            return specialMapper.listSpecialTypeFather(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return null;
    }
    @Override
    public List<PageData> listSpecialTypeFatherAll(PageData pageData) throws Exception {
        try{
            return specialMapper.listSpecialTypeFatherAll(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return null;
    }
    @Override
    public int listSpecialTypeFatherCount(PageData pageData) throws Exception {
        try{
            return specialMapper.listSpecialTypeFatherCount(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return 0;
    }

}
